
using System;
using System.Linq;
using Csla;
using Csla.Data;

namespace HousingInfo.Library
{ 
	public partial class TextHouseBOList : Csla.BusinessListBase<TextHouseBOList, TextHouseBO>
	{

		#region Authorization Rules

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of TextHouseBOList
			//AuthorizationRules.AllowCreate(typeof(TextHouseBOList), "TextHouseBOListCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(TextHouseBOList), "TextHouseBOListEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(TextHouseBOList), "TextHouseBOListDeleteGroup"));
		}
		#endregion //Authorization Rules

        #region Trang Duyet tin moi
        #region Ham lay cac tin chua duyet - Quang cao - Mien phi - Moi sua - Moi Gia han
        public static TextHouseBOList GetAllTextHouseNew(bool isactive)
        {
            return DataPortal.Fetch<TextHouseBOList>(new FilterCriteria_TextHouseNew(isactive));
        }
        #endregion
        #region Khai Bao ham
        private class FilterCriteria_TextHouseNew
        {
            public bool active;
            public FilterCriteria_TextHouseNew(bool acti)
            {
                this.active = acti;
            }
        }
        #endregion
        #region Truy cap du lieu
        private void DataPortal_Fetch(FilterCriteria_TextHouseNew param)
        {
            bool cancel = false;
            OnFetching(ref cancel);
            if (cancel) return;

            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                RaiseListChangedEvents = false;
                if (param.active == true)
                {
                    this.AddRange(
                        from row in mgr.DataContext.TextHouses
                        where row.IsActive == true
                        orderby row.CreatedDate descending
                        select TextHouseBO.GetTextHouseBO(row.TextHouseID)
                    );
                }
                else
                {
                    this.AddRange(
                        from row in mgr.DataContext.TextHouses
                        where row.IsActive == false
                        orderby row.CreatedDate descending
                        select TextHouseBO.GetTextHouseBO(row.TextHouseID)
                    );
                }

                RaiseListChangedEvents = true;
            }//using


            //OnFetched();
        }
        #endregion
        #endregion
    }
}
